package org.shadow.shapac;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;

public class Game extends Activity {
	Maze maze;
	MediaPlayer gameStart, inGame;
	
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		
		gameStart = MediaPlayer.create(Game.this, R.raw.startgame);
		inGame = MediaPlayer.create(Game.this, R.raw.mode);
		try {
			gameStart.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		gameStart.setOnCompletionListener(new OnCompletionListener() {

		        public void onCompletion(MediaPlayer player) {
		            player.stop();

		            // play next audio file
		            inGame.setLooping(true);
		            inGame.start();
		        }

		    });
		gameStart.start();
		
		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		this.maze = (Maze)getLastNonConfigurationInstance();
		if(this.maze == null) {
			this.maze = (Maze)extras.get("maze");
		}
		GameView view = new GameView(this);
		view.setMaze(this.maze);
		setContentView(view);
	}
	public Object onRetainNonConfigurationInstance() {
		return this.maze;
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		gameStart.release();
		inGame.release();
	}
	
	
}
